package com.hjl.sr.web;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hjl.sr.DefaultSecurityServer;
import com.hjl.sr.MyService;
import com.hjl.sr.YourService;

public class MyServlet extends HttpServlet {

	private static final long serialVersionUID = -3895456382730026590L;

	private DefaultSecurityServer securityServer = new DefaultSecurityServer();
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		
		securityServer.addService("myService", MyService.class, new MyServiceImpl());
		securityServer.addService("yourService", YourService.class, new YourServiceImpl());
		
		securityServer.init(config);		
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		proccess(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		proccess(req, resp);
	}

	private void proccess(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		securityServer.handleRequest(req, resp);
	}
	
}
